package com.sense.kukoo.biz_library.adapter

import com.sense.kukoo.biz_library.adapter.provider.ChannelItemProvider
import com.sense.kukoo.biz_library.adapter.provider.RecentlyUpdatedItemProvider
import com.sense.kukoo.biz_library.adapter.provider.RecentlyUpdatedTitleProvider
import com.sense.kukoo.common.media.bean.LocalMediaListItemBean
import com.sense.kukoo.common.repo.bean.SubscriptionsBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class SubscriptionsAdapter(
    data: MutableList<SubscriptionsBean>,
    val listener: SubscriptionsEventListener
) :
    MultiItemAdapter<SubscriptionsBean>(data) {

    private val TAG: String = javaClass.simpleName

    private val mRecentlyUpdatedItemProvider = RecentlyUpdatedItemProvider(listener)

    init {
        addItemProvider(ChannelItemProvider(listener))
        addItemProvider(mRecentlyUpdatedItemProvider)
        addItemProvider(RecentlyUpdatedTitleProvider())
    }

    override fun getItemType(data: MutableList<SubscriptionsBean>, position: Int): Int {
        return data.get(position).type
    }

    interface SubscriptionsEventListener {
        fun onChannelSeeAll(item: SubscriptionsBean)
        fun onChannelItemClick(item: SubscriptionsBean, position: Int)

        fun onRecentlyUpdatedItemClick(item: SubscriptionsBean)
        fun onRecentlyUpdatedPlay(item: SubscriptionsBean)
    }

    fun setCurrentMusic(music: LocalMediaListItemBean){
        mRecentlyUpdatedItemProvider.setCurrentMusic(music)
        notifyDataSetChanged()
    }

    fun setCurrentPlayState(state: Int){
        mRecentlyUpdatedItemProvider.setCurrentPlayState(state)
        notifyDataSetChanged()
    }
}